<?php


namespace App\Remote\Rms;

use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Cache;

class RmsAreaRemote extends BaseRmsRemote
{

    //添加城市等级缓存
    const CITY_GRADE_CACHE = 'TIGER_CITY_GRADE_CACHE';
    //省市区缓存
    const AREA_LIST_ALL_CACHE = 'tiger:area_list_all_cache';

    /**
     * 获取rms用户基础信息
     *
     * @param string $cityCode
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getCityGrade(string $cityCode)
    {
        if (Cache::has(RmsAreaRemote::CITY_GRADE_CACHE . $cityCode)) {
            return Cache::get(RmsAreaRemote::CITY_GRADE_CACHE . $cityCode);
        }
        $grade = self::customRequest(
            "api/internal/area/getCityGrade",
            "get",
            ["cityCode" => $cityCode]
        );
        Cache::put(RmsAreaRemote::CITY_GRADE_CACHE . $cityCode, $grade, 86400);
        return $grade;
    }

    /**
     * 获取所有省市区
     *
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getAreaListAll()
    {
        if (Cache::has(RmsAreaRemote::AREA_LIST_ALL_CACHE)) {
            return Cache::get(RmsAreaRemote::AREA_LIST_ALL_CACHE);
        }
        $areaList = self::customRequest(
            "api/internal/area/list",
            "get",
            []
        );
        Cache::put(RmsAreaRemote::AREA_LIST_ALL_CACHE, $areaList, 86400);
        return $areaList;
    }

}
